var LOC_NAVBAR = 0;
var LOC_MAINLINK = 1;
var CURRENT_LOCATION = 0;

//menu bar listener
addListener(menuBar = function(actionKey, currentLocation){
	if(currentLocation == LOC_NAVBAR){
		switch(actionKey){
			case ACTION_KEYDOWN_LEFT:
			keyDown_direction_navBar(navBarIndex, navBarIndex-getIndexIncrement());
			break;
			case ACTION_KEYDOWN_RIGHT:
			keyDown_direction_navBar(navBarIndex, navBarIndex+getIndexIncrement());
			break;
			case ACTION_KEYDOWN_UP:
			keyDown_direction_navBar(navBarIndex, navBarIndex-5);			
			break;
			case ACTION_KEYDOWN_DOWN:
			keyDown_direction_navBar(navBarIndex, navBarIndex+5);			
			break;
			case ACTION_KEYUP_ENTER:
			keyEnterNavBar();
			break;
			case ACTION_KEYDOWN_DOUBLEKEY:
			keyDoubleNavBar();
			break;
		}
	}
});

//main link listener
addListener(menuBar = function(actionKey, currentLocation){
	if(currentLocation == LOC_MAINLINK){
		switch(actionKey){
			case ACTION_KEYDOWN_DOUBLEKEY:
			keyUp_DownMainLink();
			break;
			case ACTION_KEYUP_ENTER:
			keyUp_EnterMainLink();
			break;
		}
	}
});

/****************************************/
//main link action methods
/****************************************/
function keyUp_DownMainLink(){
	CURRENT_LOCATION = LOC_NAVBAR;
	
	$('homeIcon').removeClassName('homeIconSelected');
	$('homeIcon').addClassName('homeIcon');
}

function keyUp_EnterMainLink(){
	location.href = 'index.php';
}

/****************************************/
//nav bar action methods
/****************************************/
function keyDown_direction_navBar(fromIndex, toIndex) {
	if(toIndex > (navBarItems-1)){
		var tmpIndex = fromIndex;
		navBarIndex = 0;
	} else if(toIndex < 0){
		var tmpIndex = fromIndex;
		navBarIndex = (navBarItems-1);
	}else{
		var tmpIndex = fromIndex;
		navBarIndex = toIndex;
	}
	
	an1 = new Animator({onComplete: function(){											 
							$("menuSpan"+tmpIndex).removeClassName('tvSeasonLinkOver');
							$("menuSpan"+tmpIndex).addClassName('tvSeasonLink');
							$("menuSpan"+navBarIndex).removeClassName('tvSeasonLink');
							$("menuSpan"+navBarIndex).addClassName('tvSeasonLinkOver');
						}
						}).addSubject(
	new NumericalStyleSubject(
		"navMenu",
		"margin-left",
		(((tmpIndex*-1)*columnWidth)+columnWidth),
		(((navBarIndex*-1)*columnWidth))+columnWidth)).addSubject(
	new ColorStyleSubject(
		"menuSpan"+tmpIndex,
		"color",
		'#FFFFFF',
		'#666666')).addSubject(
	new ColorStyleSubject(
		"menuSpan"+navBarIndex,
		"color",
		'#666666',
		'#FFFFFF'));
	
	an1.toggle();
	
	selectSeason(navBarIndex);
}

function keyEnterNavBar() {
	var td = $("menuTD"+navBarIndex);
	location.href = td.readAttribute('link');
}

function keyDoubleNavBar(){
	CURRENT_LOCATION = LOC_MAINLINK;
	
	$('homeIcon').removeClassName('homeIcon');
	$('homeIcon').addClassName('homeIconSelected');
}